﻿using IRepositories;
using iService;
using Repositories;
using Service.BASE;
using swiftCode.Bbs.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Service
{
    public class ModuleService : BaseServices<Module>, IModuleService
    {
        //public IModuleRepositories dal = new ModuleRepositories();
        public readonly IModuleRepositories dal;
        public ModuleService(IModuleRepositories dalRep)
        {
            dal = dalRep;
        }
        public async Task<Module> AddNewModule(Module module, bool autoSave = false)
        {
            return await dal.InsertAsync(module, autoSave);
        }

        public async Task DeleteModule(Expression<Func<Module, bool>> expression, bool autoSave = false)
        {
            await dal.DeleteAsync(expression, autoSave);
        }

        public async Task<Module> FindModule(Expression<Func<Module, bool>> expression)
        {
            return await dal.GetAsync(expression);
        }

        public async Task<List<Module>> GetAllModules()
        {
            return await dal.GetListAsync();
        }

        public async Task<Module> GetModule(Expression<Func<Module, bool>> expression)
        {
            return await dal.GetAsync(expression);
        }

        public async Task<Module> UpdateModule(Module module, bool autoSave = false)
        {
            var updatedModule = await dal.UpdateAsync(module, autoSave);
            return updatedModule;
        }
    }
}
